//
//  HelperVierController.m
//  kankanVideo
//
//  Created by wangbo on 7/12/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "HelperVierController.h"

@implementation HelperVierController
@synthesize sv;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

-(void)dealloc{
    [sv release];
    [super dealloc];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    sv.pagingEnabled=YES;
    [sv setContentSize:CGSizeMake(1024*3, 748)];
    //sv setContentOffset:CGPointMake(0, <#CGFloat y#>)
    UIImageView *img1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"helper1.jpg"]];
    [img1 setFrame:CGRectMake(0, 0, 1024, 748)];
    [sv addSubview:img1];
    [img1 release];
    UIImageView *img2=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"helper2.jpg"]];
    [img2 setFrame:CGRectMake(1024, 0, 1024, 748)];
    [sv addSubview:img2];
    [img2 release];
    UIImageView *img3=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"helper3.jpg"]];
    [img3 setFrame:CGRectMake(1024*2, 0, 1024, 748)];
    [sv addSubview:img3];
    [img3 release];
    sv.delegate=self;
    //[sv addSubview:img1];
}

-(void)viewWillAppear:(BOOL)animated{
    [sv setContentOffset:CGPointMake(0, 0) animated:NO];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //NSLog(@"=============%f",scrollView.contentOffset.x);
    if(scrollView.contentOffset.x>1024*2+20){
        [self dismissModalViewControllerAnimated:YES];
    }
    if (scrollView.contentOffset.x>1024*2) {
        [sv setContentOffset:CGPointMake(1024*2, 0) animated:NO];
    }else if(scrollView.contentOffset.x<0){
        //scrollView.contentOffset.x=0;
        [sv setContentOffset:CGPointMake(0, 0) animated:NO];
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@end
